package de.g18.llmaa.gui.lizenzTree;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import de.g18.llmaa.gui.workspace.internalFrame.lizenzUebersicht.treeTable.MyAbstractTreeNode;
import de.g18.llmaa.logic.vos.VOKey;
import de.g18.llmaa.logic.vos.VOProduct_Key;

public class TreeNode_Product extends MyAbstractTreeNode implements
		ActionListener {

	private VOProduct_Key product;
	Object[] children;

	public TreeNode_Product(VOProduct_Key product) {
		this.product = product;
		setUserObject(product.getProduct_Name());

		initKeys();
	}

	private void initKeys() {
		for (VOKey key : product.getList_Key()) {

			this.add(new TreeNode_Key(key));
		}

	}

	/**
	 * Returns the the string to be used to display this leaf in the JTree.
	 */
	public String toString() {
		return product.getProduct_Name();
	}

	/**
	 * Loads the children, caching the results in the children ivar.
	 */
	public Object[] getChildren() {

		if (children != null) {

			return children;
		}
		try {

			// String[] files = (String[]) product.getList_Key().toArray();
			if (product.getList_Key().size() >= 0) {
				// fileMS.sort(files);
				children = new TreeNode_Key[product.getList_Key().size()];
				// String path = file.getPath();

				for (int i = 0; i < product.getList_Key().size(); i++) {
					// File childFile = new File(path, files[i]);
					children[i] = new TreeNode_Key((VOKey) product
							.getList_Key().toArray()[i]);
				}
			}
		} catch (SecurityException se) {

		}
		return children;
		// return super.getPath();
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		// TODO Auto-generated method stub

	}

	public VOProduct_Key getProduct() {
		return product;
	}

}
